from src.core import Core
from flask import request
from src.schema import Schema
from src.api.origin import basic_decorator
from flask_jwt_extended import jwt_required
from src.api.origin import admin_permission
from src.api.origin import capture_exception
from src.core.variables.status import (
    ERROR_CODE,
    ERROR_CODE_CUSTOMIZE,
    SUCCESS_CODE,
    SUCCESS_CODE_CUSTOMIZE,
)


@basic_decorator(multi_nodes=True)
def close_sse(user):
    """关闭所有SSE连接"""
    try:
        schema = Schema.close_sse(**request.get_json(force=True))
        return Core.close_sse(schema.sse_id_s)
    except Exception as e:
        return ERROR_CODE_CUSTOMIZE(f"关闭SSE连接失败: {str(e)}", 500)


@basic_decorator()
def function_control(user, ):
    """功能控制"""
    schema = Schema.function_control(**request.get_json(force=True))
    return Core.function_control(schema)


@basic_decorator()
def start_self(user, ):
    """自启动"""
    schema = Schema.start_self(**request.get_json(force=True))
    return Core.start_self(schema)


